draw: call vfunc rather then emit signal for the common case
authorAlexander Larsson <alexl@redhat.com>
Mon, 14 Sep 2015 09:36:43 +0000 (11:36 +0200)
committerAlexander Larsson <alexl@redhat.com>
Mon, 14 Sep 2015 11:18:56 +0000 (13:18 +0200)
This avoids a lot of overhead in the common case where a signal
is not connected and we're just using the class vfunc (which is true
for all in-libgtk widgets). Additionally it makes backtraces in
debuggers and profiles much much nicer to look at.

https://bugzilla.gnome.org/show_bug.cgi?id=754986

gtk/gtkwidget.c

index ef279f49788911c4c6b9709effb4b4e60c36f4e9..4206c40682b0eecdc490e76281ef55b85f725d07 100644 (file)
@@ -6834,9 +6834,18 @@ _gtk_widget_draw_internal (GtkWidget *widget,
 
       gdk_window_mark_paint_from_clip (window, cr);
 
-      g_signal_emit (widget, widget_signals[DRAW],
-                     0, cr,
-                     &result);
+      if (g_signal_has_handler_pending (widget, widget_signals[DRAW], 0, FALSE))
+        {
+          g_signal_emit (widget, widget_signals[DRAW],
+                         0, cr,
+                         &result);
+        }
+      else if (GTK_WIDGET_GET_CLASS (widget)->draw)
+        {
+          cairo_save (cr);
+          GTK_WIDGET_GET_CLASS (widget)->draw (widget, cr);
+          cairo_restore (cr);
+        }
 
 #ifdef G_ENABLE_DEBUG
       if (GTK_DEBUG_CHECK (BASELINES))